package cn.xiaoniu.day05;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import cn.xiaoniu.day05.bean.Request;
import cn.xiaoniu.day05.bean.Response;
import cn.xiaoniu.day05.bean.User;

/**
 * 客户端
 * 1：建立一个连接
 * 2：发送参数对象，发送数据
 * 3：返回结果
 * @author root
 *
 */
public class Client {
	public static void main(String[] args) {
		try {
			Socket socket = new Socket("localhost", 9999);
			//得到输出流
			ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
			//封装参数
			User user = new User();
			user.set(0, "peiqi1", "xiaozhu", 0, " ");
			
			Request req = new Request();
			req.setClassName("cn.xiaoniu.day05.service.impl.UserServiceImpl");
			req.setMothedName("login");
			req.setClassType(new Class[]{User.class});
			req.setValue(new Object[]{user});
			
			//发送数据给server
			oos.writeObject(req);
			oos.flush();
			
			//接受数据
			ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
			Response resp = (Response)ois.readObject();
			System.out.println(resp);
			
			//释放资源
			socket.shutdownInput();
			socket.shutdownOutput();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
